package com.jeecg.p3.divination.service.impl;

import com.jeecg.p3.baseApi.service.BaseApiActTxtService;
import com.jeecg.p3.divination.dao.WxActDivinationDao;
import com.jeecg.p3.divination.def.DivinationProperties;
import com.jeecg.p3.divination.entity.WxActDivination;
import com.jeecg.p3.divination.service.WxActDivinationService;
import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("wxActDivinationService")
public class WxActDivinationServiceImpl implements WxActDivinationService {
	@Resource
	private WxActDivinationDao wxActDivinationDao;
	@Autowired
	private BaseApiActTxtService baseApiActTxtService;

	@Override
	@Transactional(rollbackFor=Exception.class)
	public void doAdd(WxActDivination wxActDivination) {
		wxActDivination.setProjectCode("divination");
		wxActDivinationDao.insert(wxActDivination);
		baseApiActTxtService.copyActText(DivinationProperties.TXT_ACTID_KEY, wxActDivination.getId());
	}

	@Override
	public void doEdit(WxActDivination wxActDivination) {
		wxActDivinationDao.update(wxActDivination);
	}

	@Override
	@Transactional(rollbackFor=Exception.class)
	public void doDelete(String id) {
		wxActDivinationDao.delete(id);
		baseApiActTxtService.batchDeleteByActCode(id);
	}

	@Override
	public WxActDivination queryById(String id) {
		WxActDivination wxActDivination= wxActDivinationDao.get(id);
		return wxActDivination;
	}

	@Override
	public PageList<WxActDivination> queryPageList(
		PageQuery<WxActDivination> pageQuery) {
		PageList<WxActDivination> result = new PageList<WxActDivination>();
		Integer itemCount = wxActDivinationDao.count(pageQuery);
		PageQueryWrapper<WxActDivination> wrapper = new PageQueryWrapper<>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
		List<WxActDivination> list = wxActDivinationDao.queryPageList(wrapper);
		Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
		result.setPagenation(pagenation);
		result.setValues(list);
		return result;
	}
	
}
